package simbot.example.demo.listener;

import com.alibaba.fastjson.JSONObject;
import love.forte.catcode.CatCodeUtil;
import love.forte.simbot.annotation.*;
import love.forte.simbot.api.message.events.*;
import love.forte.simbot.api.sender.MsgSender;
import love.forte.simbot.filter.MatchType;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import simbot.example.demo.entity.Setu;
import simbot.example.demo.entity.UserInfo;
import simbot.example.demo.robot.*;
import simbot.example.demo.service.UserService;
import simbot.example.demo.texasholdem.Dealer;
import simbot.example.demo.texasholdem.Player;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * 测试监听器。
 * 在未配置simbot依赖扫描的情况下，应当使用Springboot的依赖管理注解，例如@Component。
 * @author ForteScarlet
 */
@Component
public class MyListener {

    @Autowired
    UserService userService;

    /**
     * 监听私聊消息。
     */
    /*@OnPrivate
    public void privateListen(PrivateMsg privateMsg, MsgSender sender){
        // 复读私聊的信息。
        privateMsg.getMsgContent().getMsg();

        System.out.println(privateMsg.getMsgContent().getMsg());
        sender.SENDER.sendPrivateMsg(privateMsg,privateMsg.getMsgContent().getMsg());
    }*/

    final CatCodeUtil catUtil = CatCodeUtil.INSTANCE;

    // 请求音乐的线程池。
    private Executor exec = Executors.newFixedThreadPool(16);

    //启动的时候触发
    /*@PostConstruct
    public void test(){
        System.out.println("xxxxtest");
    }*/

    /**
     * 监听私聊消息。
     */
    /*@OnPrivate
    @Filter(value = "QQ", matchType = MatchType.STARTS_WITH)
    public void privateListen1(PrivateMsg privateMsg, MsgSender sender){
        String QQ="1";
        if(StringUtils.isNotBlank(privateMsg.getMsg())&&privateMsg.getMsg().contains("QQ")){
            QQ=privateMsg.getMsg().substring(2);
        }
        System.out.println(QQ);
        if(QQ.equals("1")){
            sender.SENDER.sendPrivateMsg(privateMsg,"test");
        }
        String result=userService.getUserS(QQ);

        if(privateMsg.getAccountInfo().getAccountCodeNumber()!=(285834095)){
            result="权限不够！";
        }

        sender.SENDER.sendPrivateMsg(privateMsg,result);
        //sender.SENDER.sendPrivateMsg(privateMsg, privateMsg.getMsgContent());
    }*/

    /**
     * 私聊的帮助中心
     */
    @OnPrivate
    @Filter(value = ".h", matchType = MatchType.STARTS_WITH)
    public void privateListenH(PrivateMsg privateMsg, MsgSender sender){

        String result="[CAT:rich,content={\"app\":\"com.tencent.miniapp\"&#44;" +
                "\"desc\":\"\"&#44;\"view\":\"notification\"&#44;" +
                "\"ver\":\"0.0.0.1\"&#44;\"prompt\":\"&#91;应用&#93;" +
                "\"&#44;\"meta\":{\"notification\":{\"appInfo\":" +
                "{\"appName\":\"公众号:祖安键圣\"&#44;\"appType\":4&#44;" +
                "\"appid\":1109659848&#44;" +
                "\"iconUrl\":\"https://oscimg.oschina.net/oscnet/up-ec35f6b7650829e510e57b68250bf308.jpg!/both/50x50\"}&#44;" +
                //"\"data\":&#91;{\"title\":\"米娜桑\"&#44;\"value\":\"下面是帮助指令大全\"}&#93;&#44;" +
                "\"data\":&#91;{\"title\":\"获得经验：0\"&#44;\"value\":\"下面是帮助指令大全(公众号缺工具人哦！)\"}&#93;&#44;" +
                "\"title\":\"(公众号中有各种工具以及小玩具)\"&#44;\"button\":&#91;" +
                "{\"name\":\"setu：P站图\"&#44;\"action\":\"\"}&#44;" +
                "{\"name\":\"mmd：i站MMD\"&#44;\"action\":\"\"}&#44;" +
                "{\"name\":\"bk：获取博客地址\"&#44;\"action\":\"\"}&#44;" +
                "{\"name\":\"公众号缺工具人哦！\"&#44;\"action\":\"\"}&#93;&#44;" +
                "\"emphasis_keyword\":\"\"}}}]";

        sender.SENDER.sendPrivateMsg(privateMsg,result+'\n');
    }

    /**
     * i站MMD
     */
    @OnPrivate
    @Filter(value = "mmd", matchType = MatchType.STARTS_WITH)
    public void privateListenMMD(PrivateMsg privateMsg, MsgSender sender){
        Map<String, String> header = new HashMap<String, String>();
        header.put("Host", "searchcustomerexperience.techtarget.com");
        header.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36");
        header.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
        header.put("Accept-Language", "zh-cn,zh;q=0.5");
        header.put("Accept-Encoding", "gzip, deflate");
        header.put("Cache-Control", "max-age=0");
        header.put("Connection", "keep-alive");

        String keyword="";
        int len=3;
        if(privateMsg.getMsg().length()>len){
            keyword=privateMsg.getMsg().substring(3);
        }else {
            sender.SENDER.sendPrivateMsg(privateMsg,"格式错误,格式:mmd弱音"+'\n');
            return;
        }
        Util.init();
        String url="https://www.iwara.tv/search?query="+keyword+"&page=0";//分页&page=1
        String result="";
        try {
            Document document = Jsoup.connect(url).headers(header).timeout(8000).ignoreContentType(true).get();
            Elements urls=document.select("a");
            for (Element link : urls) {
                String linkHref = link.attr("href");
                if(linkHref.contains("/videos/")){
                    String urlss="https://www.iwara.tv"+linkHref+"";
                    result+='\b'+" "+"\n"+urlss;
                }
            }
        }catch (Exception e){
            sender.SENDER.sendPrivateMsg(privateMsg,"数据异常");
            return;
        }

        System.out.println("MMD:"+result);
        sender.SENDER.sendPrivateMsg(privateMsg,result);
    }


    /**
     * 轰炸机
     */
    @OnGroup
    @Filter(value = "hz", matchType = MatchType.STARTS_WITH)
    public void groupMsg4(GroupMsg groupMsg, MsgSender sender){
        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber()+"");
        String phone=groupMsg.getMsg().substring(2);
        String regex = "(1|861)([0-9])\\d{9}$*";

        // 编译正则表达式
        Pattern pattern = Pattern.compile(regex);
        // 创建给定输入模式的匹配器
        Matcher matcher = pattern.matcher(phone);
        boolean bool = matcher.matches();
        try {
            if(bool) { // 如果验证通过
                System.out.println("输入的电话号码格式正确。");
                sender.SENDER.sendGroupMsg(groupMsg,at+"防止繁用禁言中... ...");
                //禁言处理
                if(groupMsg.getAccountInfo().getAccountCodeNumber()!=285834095){
                    sender.SETTER.setGroupBan(String.valueOf(groupMsg.getGroupInfo().getGroupCodeNumber()), String.valueOf(groupMsg.getAccountInfo().getAccountCodeNumber()), 300, TimeUnit.SECONDS);
                }
                String result=userService.dxhz(phone);
                sender.SENDER.sendGroupMsg(groupMsg, result);
            } else {
                sender.SENDER.sendGroupMsg(groupMsg,"笨蛋,格式错误了！");
            }
        }catch (Exception e){
            if(bool) { // 如果验证通过
                System.out.println("输入的电话号码格式正确。");
                sender.SENDER.sendGroupMsg(groupMsg,at+"禁言失败,hz中... ...");
                String result=userService.dxhz(phone);
                sender.SENDER.sendGroupMsg(groupMsg, result);
            } else {
                sender.SENDER.sendGroupMsg(groupMsg,"笨蛋,格式错误了！");
                return;
            }
        }
    }

    String help="米娜桑,帮助指令有.h调出帮助指令大全"+'\n'
            +"setu：P站图"+'\n'+
            "hz：后面接phone"+'\n'+
            "加入：加入三人游戏"+'\n'+
            "薛定谔式禁言：禁言目标QQ,\n " +
            "有几率禁言自己60秒(70%), " +
            "\n也有几率禁言目标(30%)," +
            "还有20%几率暴击"+'\n'+
            "at：随机中二发言"+'\n'+
            "fy：网易翻译,格式(fymusic)"+'\n'+
            "xh：随机笑话"+'\n'+
            "dg：网易云随机歌曲"+'\n'+
            "jt：鸡汤(emmm真香)"+'\n'+
            "qh：一句话土味情话"+'\n'+
            "rj：需要的大多数软件,格式：(rj小说)"+'\n'+
            "sh：骚话(富萝莉我要富萝莉)"+'\n'+
            "gs：随机古诗"+'\n'+
            "bk：获取博客地址"+'\n'+
            "公众号：祖安键圣 \n" +
            "(公众号中有各种工具以及小玩具)"+'\n'+
            "顺便缺工具人哦！";

    /**
     * 被at
     * */
    @OnGroup
    @Filter(atBot=true, matchType = MatchType.STARTS_WITH)
    public void groupMsg6(GroupMsg groupMsg, MsgSender sender){
        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber()+"");
        String url3="";
        Util.init();
        try {
            String url="https://v1.hitokoto.cn/?c=a&c=b&c=c";
            Util.init();
            Document document = Jsoup.connect(url)
                    .method(Connection.Method.GET)
                    .ignoreContentType(true).get();
            String html = document.body().text();
            String content=JSONObject.parseObject(html).getString("hitokoto");
            String img="[CAT:image,url=http://c2cpicdw.qpic.cn/offpic_new/285834095//285834095-4118566523-2067D97791543866D45BC928363E23FE/0?term=2]";
            sender.SENDER.sendGroupMsg(groupMsg," "+at+"\n"+" "+'\n'+content+"\n"+img);
        }catch (Exception e){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"艾特都不会,笨蛋！"+'\n');
            return;
        }
    }

    /**
     * 获取博客的卡片
     * */
    @OnGroup
    @Filter(value = "bk", matchType = MatchType.STARTS_WITH)
    public void groupMsg20(GroupMsg groupMsg, MsgSender sender){
        String result ="";

        result="[CAT:rich,content={ \"app\": \"com.tencent.gxhServiceIntelligentTip\"&#44;" +
                " \"config\": { \"autosize\": 1&#44; \"ctime\": 1618137193&#44; " +
                "\"forward\": 1&#44; \"token\": \"1e2e8d8171641d2f5afdfc4748ce6cf8\"&#44; \"type\": \"normal\" }&#44; " +
                "\"desc\": \"\"&#44; \"meta\": { \"gxhServiceIntelligentTip\": " +
                "{ \"action\": \"http:\\/\\/120.77.33.251\"&#44;" +
                " \"appid\": \"gxhServiceIntelligentTip\"&#44; \"bgImg\": \"http:\\/\\/gchat.qpic.cn\\/gchatpic_new\\/3584906133\\/956021029-2885039703-7B5004A5ED0FCF042BF5AF737EA1762B\\/0?term=2\"&#44;" +
                " \"reportParams\": null } }&#44; " +
                "\"prompt\": \"憨批！\"&#44; \"ver\": \"1.0.0.1\"&#44; \"view\": \"gxhServiceIntelligentTip\" }]";
        exec.execute(() -> {

        });
        sender.SENDER.sendGroupMsg(groupMsg,"http://120.77.33.251");
        sender.SENDER.sendGroupMsg(groupMsg,result);
    }

    /**
     * 群成员增加IncreaseEventGet
     */
    @Listen(value = GroupMemberIncrease.class)
    public void groupMsg8(GroupMemberIncrease groupMsg, MsgSender sender){
        
        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber());
        try {
            String url="https://v1.hitokoto.cn/?c=a&c=b&c=c";
            Util.init();
            Document document = Jsoup.connect(url)
                    .method(Connection.Method.GET)
                    .ignoreContentType(true).get();
            String html = document.body().text();
            String content=JSONObject.parseObject(html).getString("hitokoto");
            sender.SENDER.sendGroupMsg(groupMsg," "+at+"\n"+" "+help+'\n'+content);
        }catch (Exception e){
            sender.SENDER.sendGroupMsg(groupMsg," 捕获失败！");
            return;
        }
    }

    /**
     * 好友增加事件
     */
    @Listen(value = FriendIncrease.class)
    public void groupMsg8(FriendIncrease groupMsg, MsgSender sender){
        try {
            String url="https://v1.hitokoto.cn/?c=a&c=b&c=c";
            Util.init();
            Document document = Jsoup.connect(url)
                    .method(Connection.Method.GET)
                    .ignoreContentType(true).get();
            String html = document.body().text();
            String content=JSONObject.parseObject(html).getString("hitokoto");
            sender.SENDER.sendPrivateMsg(groupMsg,"\n"+" "+help+'\n'+content);
        }catch (Exception e){
            sender.SENDER.sendPrivateMsg(groupMsg," 捕获失败！");
            return;
        }
    }

    /**
     * 笑话
     */
    @OnGroup
    @Filter(value = "xh", matchType = MatchType.STARTS_WITH)
    public void groupMsg10(GroupMsg groupMsg, MsgSender sender) {
        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber());
        String url3="http://dl.kegood.com/jsapi/api.php?lmapi=1&sjlm=99&bm=utf&apikey=oaih8646kisulhgklsdfn6541615i";
        try {
            Document document = Jsoup.connect(url3).ignoreContentType(true).get();
            String html = document.body().text();
            JSONObject jsonObject = JSONObject.parseObject(html);
            //标题
            String j1=jsonObject.getJSONObject("data").getString("apileibie");
            String decode1 = java.net.URLDecoder.decode(j1,"utf-8");
            //内容
            String j2=jsonObject.getJSONObject("data").getString("apineirong");
            String decode2 = java.net.URLDecoder.decode(j2,"utf-8").replace("</p>","\n");
            String result="标题:"+decode1+"\n"+" 内容:"+decode2;
            System.out.println(result);
            sender.SENDER.sendGroupMsg(groupMsg," "+at+"\n"+" "+result);
            return;
        }catch (Exception e){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"被玩坏了,呜呜呜！");
            return;
        }
    }

    /**
     * 情话
     */
    @OnGroup
    @Filter(value = "qh", matchType = MatchType.STARTS_WITH)
    public void groupMsg15(GroupMsg groupMsg, MsgSender sender) {
        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber());
        String url3="https://res.abeim.cn/api-text_sweet?export=json";
        try {
            Document document = Jsoup.connect(url3).ignoreContentType(true).get();
            String html = document.body().text();
            JSONObject jsonObject = JSONObject.parseObject(html);
            //内容
            String j2=jsonObject.getString("content");
            System.out.println("情话:"+j2);
            sender.SENDER.sendGroupMsg(groupMsg," "+at+"\n"+" "+j2);
            return;
        }catch (Exception e){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"被玩坏了,呜呜呜！");
            return;
        }
    }

    /**
     * 翻译
     */
    @OnGroup
    @Filter(value = "fy", matchType = MatchType.STARTS_WITH)
    public void groupMsg17(GroupMsg groupMsg, MsgSender sender) {
        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber());
        try {
            String keyword=groupMsg.getMsg().substring(2);
            String url3="http://api.wpbom.com/api/trans.php?msg="+keyword;
            Document document = Jsoup.connect(url3).ignoreContentType(true).get();
            String html = document.body().text();
            //JSONObject jsonObject = JSONObject.parseObject(html);
            sender.SENDER.sendGroupMsg(groupMsg," "+at+"\n"+" "+html);
            return;
        }catch (Exception e){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"被玩坏了,呜呜呜！");
            return;
        }
    }

    /**
     * 点歌
     */
    @OnGroup
    @Filter(value = "dg", matchType = MatchType.STARTS_WITH)
    public void groupMsg11(GroupMsg groupMsg, MsgSender sender) {

        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber());
        String url3="";
        try {
            double d = Math.random();
            int i = (int)(d*10);
            if(i>4){
                url3="https://api.uomg.com/api/rand.music?mid=443797814&format=json";
            }else {
                url3="https://api.uomg.com/api/rand.music?mid=377536776&format=json";
            }
            Document document = Jsoup.connect(url3).ignoreContentType(true).get();
            String html = document.body().text();
            JSONObject jsonObject = JSONObject.parseObject(html).getJSONObject("data");
            //url
            String url=jsonObject.getString("url");
            //name
            String name=jsonObject.getString("name");
            //image
            String image=jsonObject.getString("picurl");
            System.out.println(name+":"+url);
            //String music=catUtil.toCat("share","url="+url,"title="+name,"image="+image);
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" \n"+" 歌曲名:\n"+name+" \n 下载地址:"+url);
            return;
        }catch (Exception e){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"被玩坏了,呜呜呜！");
            return;
        }
    }

    /**
     * 古诗
     */
    @OnGroup
    @Filter(value = "gs", matchType = MatchType.STARTS_WITH)
    public void groupMsg12(GroupMsg groupMsg, MsgSender sender){
        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber());
        String url3="";
        try {
            url3="https://v1.alapi.cn/api/shici?type=all";
            Document document = Jsoup.connect(url3).ignoreContentType(true).get();
            String html = document.body().text();
            JSONObject jsonObject = JSONObject.parseObject(html).getJSONObject("data");
            String content=jsonObject.getString("content");
            String origin=jsonObject.getString("origin");
            String author=jsonObject.getString("author");
            String category=jsonObject.getString("category");
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"类型："+category+'\n'+"作者："+author+'\n'+"标题:"+origin+'\n'+"内容:"+content+'\n');
            return;
        }catch (Exception e){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"被玩坏了,呜呜呜！");
            return;
        }
    }

    /**
     * 红包
     */
    @OnGroup
    @Filter(value = "hb", matchType = MatchType.STARTS_WITH)
    public void groupMsg18(GroupMsg groupMsg, MsgSender sender){
        String result="[CAT:rich,content={\"app\":\"com.tencent.miniapp\"&#44;" +
                "\"desc\":\"\"&#44;\"view\":\"all\"&#44;\"ver\":\"1.0.0.89\"&#44;" +
                "\"prompt\":\"&#91;QQ红包&#93;恭喜发财\"&#44;" +
                "\"meta\":{\"all\":{\"preview\":\"http:\\/\\/gchat.qpic.cn\\/gchatpic_new\\/3584906133\\/956021029-2885039703-7B5004A5ED0FCF042BF5AF737EA1762B\\/0?term=2\"&#44;" +
                "\"title\":\"\"&#44;\"buttons\":&#91;{\"name\":\"无产阶级红包\"&#44;\"action\":\"http:\\/\\/www.qq.com\"}&#93;" +
                "&#44;\"jumpUrl\":\"\"&#44;" +
                "\"summary\":\"\\n发了送一个 <无产阶级红包>  无论使用哪个版本的手机QQ均不能查收红包  因为无产阶级的果实不能靠别人施舍  是靠自己争取的！\\n\"}}&#44;" +
                "\"config\":{\"forward\":true}}]";
        sender.SENDER.sendGroupMsg(groupMsg," "+result);
        return;
    }

    /**
     * 骚话
     */
    @OnGroup
    @Filter(value = "sh", matchType = MatchType.STARTS_WITH)
    public void groupMsg13(GroupMsg groupMsg, MsgSender sender){
        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber());
        String url3="";
        try {
            String url="https://api.vvhan.com/api/sao";
            Document document = Jsoup.connect(url)
                        .method(Connection.Method.GET)
                        .ignoreContentType(true).get();
            String html = document.body().text();
            //JSONObject jsonObject = JSONObject.parseObject(html);
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"骚话："+html+" ");
            return;
        }catch (Exception e){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"被玩坏了,呜呜呜！");
            return;
        }
    }

    /**
     * win10 bug
     * */
    @OnGroup
    @Filter(value = "bug", matchType = MatchType.STARTS_WITH)
    public void groupMsg19(GroupMsg groupMsg, MsgSender sender){
        String at = "www.\\\\.\\globalroot\\device\\condrv\\kernelconnect";
        sender.SENDER.sendGroupMsg(groupMsg,"  "+"\n"+""+at);
        return;
    }

    /**
     * 帮助
     */
    @OnGroup
    @Filter(value = ".h", matchType = MatchType.STARTS_WITH)
    public void groupMsg14(GroupMsg groupMsg, MsgSender sender) {
        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber());
        try {
            String url="https://v1.hitokoto.cn/?c=a&c=b&c=c";
            Util.init();
            Document document = Jsoup.connect(url)
                    .method(Connection.Method.GET)
                    .ignoreContentType(true).get();
            String html = document.body().text();
            String content=JSONObject.parseObject(html).getString("hitokoto");

            String result="[CAT:rich,content={\"app\":\"com.tencent.miniapp\"&#44;" +
                    "\"desc\":\"\"&#44;\"view\":\"notification\"&#44;" +
                    "\"ver\":\"0.0.0.1\"&#44;\"prompt\":\"&#91;应用&#93;" +
                    "\"&#44;\"meta\":{\"notification\":{\"appInfo\":" +
                    "{\"appName\":\"公众号:祖安键圣\"&#44;\"appType\":4&#44;" +
                    "\"appid\":1109659848&#44;" +
                    "\"iconUrl\":\"https://oscimg.oschina.net/oscnet/up-ec35f6b7650829e510e57b68250bf308.jpg!/both/50x50\"}&#44;" +
                    //"\"data\":&#91;{\"title\":\"米娜桑\"&#44;\"value\":\"下面是帮助指令大全\"}&#93;&#44;" +
                    "\"data\":&#91;{\"title\":\"获得经验：538\"&#44;\"value\":\"下面是帮助指令大全(公众号缺工具人哦！)\"}&#93;&#44;" +
                    "\"title\":\"(公众号中有各种工具以及小玩具)\"&#44;\"button\":&#91;" +
                    "{\"name\":\"setu：P站图\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"hz：后面接phone\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"加入：加入三人游戏\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"薛定谔式禁言：禁言目标QQ\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"at：随机中二发言\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"fy：网易翻译;格式(fymusic)\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"xh：随机笑话\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"dg：网易云随机歌曲\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"jt：鸡汤(emmm真香)\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"qh：一句话土味情话\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"rj：需要的大多数软件;格式：(rj小说)\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"sh：骚话(富萝莉我要富萝莉)\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"hb：无产阶级红包\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"bk：获取博客地址\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"kc：输入车牌搜磁力(格式kcipx641)\"&#44;\"action\":\"\"}&#44;" +
                    "{\"name\":\"gs：随机古诗\"&#44;\"action\":\"\"}&#93;&#44;" +
                    "\"emphasis_keyword\":\"\"}}}]";
            //sender.SENDER.sendGroupMsg(groupMsg," "+at+"\n"+" "+help+'\n'+content);
            sender.SENDER.sendGroupMsg(groupMsg," "+result+'\n');
            sender.SENDER.sendGroupMsg(groupMsg," "+at+"\n"+content);

        }catch (Exception e){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"被玩坏了,呜呜呜！");
            return;
        }
    }

    /**
     * 鸡汤
     */
    @OnGroup
    @Filter(value = "jt", matchType = MatchType.STARTS_WITH)
    public void groupMsg7(GroupMsg groupMsg, MsgSender sender) {
        Map<String, String> header = new HashMap<String, String>();
        header.put("Host", "searchcustomerexperience.techtarget.com");
        header.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36");
        header.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
        header.put("Accept-Language", "zh-cn,zh;q=0.5");
        header.put("Accept-Encoding", "gzip, deflate");
        header.put("Cache-Control", "max-age=0");
        header.put("Connection", "keep-alive");

        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber());
        String url3="";
        try {
            String url="http://api.lkblog.net/ws/api.php";
            Document document = Jsoup.connect(url).headers(header)
                        .method(Connection.Method.GET)
                        .ignoreContentType(true).get();
            String html = document.body().text();
            JSONObject jsonObject = JSONObject.parseObject(html);
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"鸡汤："+jsonObject.getString("data")+" ");
            return;
        }catch (Exception e){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"被玩坏了,呜呜呜！");
            return;
        }
    }

    /**
     * 磁力
     */
    @OnGroup
    @Filter(value = "kc", matchType = MatchType.STARTS_WITH)
    public void groupMsg21(GroupMsg groupMsg, MsgSender sender) {

        String at = catUtil.toCat("at","code="+groupMsg.getAccountInfo().getAccountCodeNumber());
        String keyword="";
        int len=2;
        if(groupMsg.getMsg().length()>len){
            keyword=groupMsg.getMsg().substring(len);
        }
        String url12="http://clb5.net/s/"+keyword+".html";
        String url="http://clg88.net/search?word="+keyword;

        if(1==1){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+url+"\n"+url12);
            return;
        }

        Map<String, String> header = new HashMap<String, String>();
        header.put("Host", "searchcustomerexperience.techtarget.com");
        header.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36");
        header.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
        header.put("Accept-Language", "zh-cn,zh;q=0.5");
        header.put("Accept-Encoding", "gzip, deflate");
        header.put("Cache-Control", "max-age=0");
        header.put("Connection", "keep-alive");

        Util.init();
        Document document = null;
        try {
            document = Jsoup.connect(url).headers(header)
                    .timeout(50000).ignoreContentType(true).get();
        } catch (IOException e) {
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"被玩坏了,呜呜呜！");
            return;
        }
        Elements urls=document.select("a");
        String result="车车:";
        for (Element link : urls) {
            String linkHref = link.attr("href");
            if (linkHref.contains("/detail/")) {
                //linkHref = "http://clb5.net/" + linkHref;
                linkHref = "http://clg88.net/search?word=" + linkHref;
                //System.out.println("html2 :"+linkHref);
                Document document1 = null;
                try {
                    document1 = Jsoup.connect(linkHref).headers(header)
                            .timeout(50000).ignoreContentType(true).get();
                    Elements urls1 = document1.select("a");
                    for (Element link1 : urls1) {
                        String url1 = link1.attr("href");
                        if (url1.contains("magnet")) {
                            System.out.println("html1 :" + url1);
                            result=result+"\n"+url1+"\n";
                        }
                    }
                } catch (IOException e) {

                }
            }
        }
        if(result.length()>5){
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+result+" ");
            return;
        }else{
            sender.SENDER.sendGroupMsg(groupMsg," "+at+" "+"\n"+"没有搜到呢！");
            return;
        }
    }


    @OnPrivate
    @Filter(value = "test", matchType = MatchType.STARTS_WITH)
    public void test1(PrivateMsg privateMsg, MsgSender sender){
        String result ="";

        result="[CAT:rich,content={ \"app\": \"com.tencent.gxhServiceIntelligentTip\"&#44;" +
                " \"config\": { \"autosize\": 1&#44; \"ctime\": 1618137193&#44; " +
                "\"forward\": 1&#44; \"token\": \"1e2e8d8171641d2f5afdfc4748ce6cf8\"&#44; \"type\": \"normal\" }&#44; " +
                "\"desc\": \"\"&#44; \"meta\": { \"gxhServiceIntelligentTip\": " +
                "{ \"action\": \"https:\\/\\/met.red\\/h\\/location/push?server=Iw4ebr2PxpsZ0iCq\"&#44;" +
                " \"appid\": \"gxhServiceIntelligentTip\"&#44; \"bgImg\": \"http:\\/\\/gchat.qpic.cn\\/gchatpic_new\\/3584906133\\/956021029-2885039703-7B5004A5ED0FCF042BF5AF737EA1762B\\/0?term=2\"&#44;" +
                " \"reportParams\": null } }&#44; " +
                "\"prompt\": \"憨批！\"&#44; \"ver\": \"1.0.0.1\"&#44; \"view\": \"gxhServiceIntelligentTip\" }]";
        exec.execute(() -> {

        });
        System.out.println("测试"+result);
        sender.SENDER.sendPrivateMsg(privateMsg,result);
    }

    //
    //获取NT
    @OnGroup
    @Filter(value = "nt", matchType = MatchType.STARTS_WITH)
    @OnPrivate
    public void getNT(GroupMsg groupMsg, MsgSender sender) {
        String url="[CAT:rich,content=<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>" +
                "<msg serviceID=\"1\" templateID=\"-1\" action=\"plugin\" a_actionData=\"mqqapi://card/show_pslcard?src_type=internal&amp;amp;source=sharecard&amp;amp;version=1&amp;amp;uin=\" " +
                " brief=\"群男酮检测报告\" sourceMsgId=\"0\" url=\"\" flag=\"2\" " +
                "adverSign=\"0\" multiMsgFlag=\"0\"><item layout=\"5\" bg=\"2\" advertiser_id=\"0\" aid=\"0\">" +
                "<title>点击查看本群男同</title></item><source name=\"\" icon=\"\" action=\"\" appid=\"-1\" />" +
                "</msg>]\n";
        exec.execute(() -> {

        });
        System.out.println("NT：");
        sender.SENDER.sendGroupMsg(groupMsg,url);

    }


}
